package com.haoniu.pay.alipay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;

/**
 * 支付宝相关支付
 */
public class AliPay {


    /**
     * 支付宝代付协议 -程鸿俊
     * @param userAliAccount
     * @param userName
     * @param transMoney
     */
    public static String merchantToUserAliAccount(String userAliAccount,String userName,String transMoney ,String aliRequestNo){
        try {
            AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","2017072107839736","MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCrMsVyDhkMfw7CCr06mfRC2MSZKFJYUuesfSZAGBum/JdvAAI+B+NunRKwJD+09Eg9zNPmkQqEFfKFzbKIgd72YF189Dnb2ssnJNta0Lt/43JrJBG//Ntf6VLea0p60EInrG79mUz4Bdbl4et5ehoWCKgLWP/yBA5vTpwfVwA2/KiRA2DIc3uX/kXYCEZWuqHmNLOBLTV3VcsaIYj7yDRpgSIIQvmmVqUmdRp/p8UN/C2pyMjGX1b6axR4Idtw0FAF3Ze3MrfSrxtTH9z97fQCIUBoBOqScg4RnXg8BHa8Cm3I3soIhvI0rLr3hx1sISSfKEXjZZGJLgbJRiXiSPCNAgMBAAECggEBAIRGpVI73FTQc0mwXIdD3vwrWrPv+LfvzrtyszRArFT4w9TrD9B37d1QldjtGSAqwwqlEXELzjFCd/G0fmaE2g5JZNKgLXhW9DLZgncH4metCIIKC4Do0WOo9vONuK1t7j+TNurRISxd7q4OQg/JLRCrPZQO/ysywSh1d6GraioRB5hmpi8q2jpWUdOnXWXBI8POVMnsEx8tbGXOe54pDIfA3JMYRnCLnbXwq0SNxf1wzj3lUt6KcTrhNltSlV9Syk3/ldX6e+3dhgaHwvrsQUE1J1fXuS1NZVODa7aYSNBzS/73cg/9huINt19CBKfGVyynmflgSfUuqz548NxY+W0CgYEA4UUFxq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EkvI51wZp2OauXrLZVXfFZTuJz0n2f2eN9zyP4kksSsLjIRhwTqtvLmhAdSXVsa9UgOGy9V8uFRclWoGZiZ607fszSk0bNDow4sQz/ZWfmv7f7OdJGj69m/woKlipVDT0a0HZVEY+QTX98IOzFNuDHKUpovhskagnyWye+++uJH51b+0KVLUV+lwIDAQAB","RSA2");
            AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
            request.setBizContent("{" +
                    "\"out_biz_no\":\""+aliRequestNo+"\"," +
                    "\"payee_type\":\"ALIPAY_LOGONID\"," +
                    "\"payee_account\":\""+userAliAccount+"\"," +
                    "\"amount\":\""+transMoney+"\"," +
                    "\"payer_show_name\":\"\"," +
                    "\"payee_real_name\":\""+userName+"\"," +
                    "\"remark\":\"商户提现\"" +
                    "  }");
            AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
            if(response.isSuccess()){
                System.out.println("调用成功");
                return "SUCCESS";
            } else {
                System.out.println("调用失败");
                return response.getSubMsg();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "FAIL";
    }

    public static void main(String[] args) {
        merchantToUserAliAccount("996993015@qq.com","程鸿俊232","200","232");
    }
}
